/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.uct.service.plugins  
 */
package com.apache.uct.service.plugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.uct.common.entity.Dept;
import com.apache.uct.manager.DeptManager;

/**
 * description:  获取部门信息按指定属性
 * @author dwusoft 创建时间：2015-3-31  
 * @Copyright(c)2014:北京--软件技术有限公司
 */
public class DeptEntityPlugin implements PluginConnector {

	private DeptManager deptManager;

	/**
	 * TODO 获取部门信息按指定属性(按部门标识查询时必须传部门所在机构ID或机构标识).  <br>
	 *   参数说明: <br>
	 *   propertyName:属性名称(deptId,deptEname,fullEname)<br>
	 *   propertyValue:属性值<br>
	 *   如果使用机构标识查询需要传orgId或orgEname
	 */
	public Object execute(ParamsVo vo) throws Exception {
		String propertyName = String.valueOf(vo.getParams("propertyName"));
		String propertyValue = String.valueOf(vo.getParams("propertyValue"));
		ResultEntity result = new ResultEntity();
		try {
			result.setResult("true");
			if ("deptId".equals(propertyName) || "deptEname".equals(propertyName) || "fullEname".equals(propertyName)) {
				ParamsVo pvo = new ParamsVo();
				pvo.setParams("propertyName", propertyName);
				pvo.setParams("propertyValue", propertyValue);
				pvo.setKey("ByProperty");
				if ("deptEname".equals(propertyName)) {
					String orgId = String.valueOf(vo.getParams("orgId"));
					String orgEname = String.valueOf(vo.getParams("orgEname"));
					pvo.setParams("orgId", orgId);
					pvo.setParams("orgEname", orgEname);
				}
				Dept dept = (Dept) deptManager.execute(pvo);
				result.setEntity(dept);
				result.setMessage("部门查询成功！");
			} else {
				result.setMessage("不支持属性" + propertyName + "的查询！");
			}
		} catch (Exception e) {
			result.setResult("false");
			result.setMessage("部门查询失败！");
		}
		return result;
	}

	public void setDeptManager(DeptManager deptManager) {
		this.deptManager = deptManager;
	}

}
